package com.atguigu.edu2021.mock.stage;

import com.atguigu.edu2021.mock.config.AppConfig;
import com.atguigu.edu2021.mock.factory.UserSession;
import com.atguigu.edu2021.mock.log.AppCommon;
import com.atguigu.edu2021.mock.log.AppDisplay;
import com.atguigu.edu2021.mock.log.AppMain;
import com.atguigu.edu2021.mock.log.AppPage;
import com.atguigu.edu2021.mock.log.enums.PageId;
import com.atguigu.mock.util.LogUtil;
import com.atguigu.mock.util.RandomNum;
import org.springframework.stereotype.Component;

import java.util.List;


@Component("mine")
public class MineStage implements Stage {
    @Override
    public boolean handle() {


        AppMain appMain= mainLog();
        LogUtil.logToJson(appMain);
        UserSession.setLastPageId(PageId.mine);
        return true;
    }



    private AppMain mainLog(){
        AppCommon appCommon = UserSession.getAppCommon();

        Integer durTime= RandomNum.getRandInt(5000, AppConfig.page_during_max_ms);

        AppPage appPage = AppPage.builder()
                .last_page_id(UserSession.getLastPageId())
                .during_time(durTime)
                .page_id(PageId.mine).build();


        List<AppDisplay> appDisplayList = AppDisplay.builder().buildList();
        UserSession.addTimeByDuringTime(appPage.getDuring_time());
        Long ts= UserSession.getCurDateTime().getTime();
        AppMain appMain = AppMain.builder().common(appCommon).page(appPage).displays(appDisplayList).ts(ts).build();
        return appMain;
    }
}
